home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
...taking it to the Macs!
/
...taking it to the Macs!.iso
/
Extras
/
ActiveX Mac SDK
/
ActiveX SDK
/
Container Common
/
CContainer.cpp
< prev
next >
Wrap
Text File
|
1997-01-03
|
4KB
|
226 lines
//
// Container.cpp
//
// Copyright (C) Microsoft Corporation, 1996
//
#include "headers.h"
#include "CContainer.h"
#include "CContainerManager.h"
#include "CXEnumGeneric.h"
//
// CXContainer::CContainer
//
// Default constructor
// If this is used then do a SetContainerParams before doing anything fancy.
//
CContainer::CContainer(void)
{
CommonInit();
}
//
// CXContainer::CContainer
//
// Parameterized constructor
//
CContainer::CContainer(CContainerManager* inOwner, PlatformPort* inHostPort)
{
CommonInit();
mHostPort = inHostPort;
mOwner = inOwner;
}
//
// CXContainer::CommonInit
//
// fill values that don't vary for constructors
//
void
CContainer::CommonInit(void)
{
mHostPort = NULL;
mCodeDownloadP = NULL;
mHostPort = NULL;
mOwner = NULL;
mSiteArrayP = new LArray( sizeof(void*));;
}
//
// CXContainer::~CContainer
//
// Destructor
//
CContainer::~CContainer()
{
// Get rid of the code download object
if (mCodeDownloadP != NULL)
{
delete mCodeDownloadP;
mCodeDownloadP = NULL;
}
// Unlink ourselves from the global list of container objects if there is one
if ( mOwner )
{
mOwner->RemoveContainer( this );
}
if ( mSiteArrayP )
delete mSiteArrayP;
}
//
// CContainer::IUnknown::QueryInterface
//
// Get an interface pointer on the object
//
STDMETHODIMP
CContainer::QueryInterface(REFIID inRefID, void** outObj)
{
ErrorCode Result = CBaseCOM::QueryInterface(inRefID, outObj);
if ( Result == E_NOINTERFACE )
{
void* pv = nil;
if ( inRefID == IID_IContainer )
pv = (void*) (IContainer*) this;
*outObj = pv;
if ( pv )
{
((IUnknown*) pv)->AddRef();
Result = S_OK;
}
}
return Result;
}
//********************** ICollection methods **********************/
//
// CContainer::ICollection::AddItem
//
void
CContainer::AddSite(CXSite *inSite)
{
mSiteArrayP->InsertItemsAt(1, 0x7fffffff, &inSite);
}
//
// CContainer::ICollection::RemoveItem
//
void
CContainer::RemoveSite(CXSite *inSite)
{
mSiteArrayP->Remove(&inSite);
}
//
// CContainer::ICollection::GetCount
//
Uint32
CContainer::GetCount(void)
{
return mSiteArrayP->GetCount();
}
//
// CContainer::ICollection::FetchItem
//
void
CContainer::FetchSite(Int16 inIndex, CXSite** outSite)
{
mSiteArrayP->FetchItemAt(inIndex, outSite);
}
//
// CContainer::EnumControls
//
// return an enumerator of controls in the container which meet the flags requirements
//
STDMETHODIMP
CContainer::EnumControls (SearchSpec* /* inSpec */, Uint32 inSearchDepth, IEnumUnknown** outEnumerator)
{
ErrorCode theResult;
Uint32 cElements;
IUnknown** punkArray;
Uint32 current;
CXSite* pSite;
CXEnumGeneric* penum;
if (inSearchDepth & OLECONTF_EMBEDDINGS) {
// Allocate as many elements as we have sites. Note that this may not
// be the true number of objects available if for some reason a site
// failed to instantiate its corresponding object.
Uint32 theSiteCount = mSiteArrayP->GetCount();
if ((punkArray = (IUnknown**) CoTaskMemAlloc(theSiteCount * sizeof(IUnknown*))) == NULL)
{
*outEnumerator = NULL;
return E_OUTOFMEMORY;
}
current = cElements = 0;
while (current < theSiteCount)
{
if (mSiteArrayP->FetchItemAt(++current, &pSite) && pSite->m_punkObject != NULL)
punkArray[cElements++] = pSite->m_punkObject;
}
}
else
{
// Return an empty enumerator if we're asked for types of objects we
// don't contain.
cElements = 0;
punkArray = NULL;
}
if ((penum = new CXEnumGeneric((void*) punkArray, cElements,
&g_EnumUnknown)) != NULL) {
// Update the reference count of all contained objects.
for (current = 0; current < cElements; current++)
punkArray[current]->AddRef();
*outEnumerator = (IEnumUnknown*)(LPENUMGENERIC) penum;
theResult = S_OK;
}
else
{
CoTaskMemFree(punkArray);
*outEnumerator = NULL;
theResult = E_OUTOFMEMORY;
}
return theResult;
}